package com.sunhaojie.pos.front.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sunhaojie.pos.common.enums.ErrorCodeEnum;
import com.sunhaojie.pos.common.exception.BussinessRuntimeException;
import com.sunhaojie.pos.common.servlet.BufferedServletRequestWrapper;
import com.sunhaojie.pos.front.bo.ForwordBo;

@Controller
public class FrontController {
	
	private static Logger logger = LoggerFactory.getLogger(FrontController.class);

	@Autowired
	private ForwordBo forwordBo;

	@ResponseBody
	@RequestMapping("**")
	public String forword(HttpServletRequest request, HttpServletResponse response) {
		String path = request.getServletPath();
		logger.info(path);
		
		BufferedServletRequestWrapper requestWrapper = null;
		try {
			requestWrapper = new BufferedServletRequestWrapper(request);
		} catch (IOException e) {
			logger.error("io错误", e);
			throw new BussinessRuntimeException(ErrorCodeEnum.HTTP_CLIENT_IO_ERROR);
		}
		
		
		
		return forwordBo.forward(path, requestWrapper.getMethod(), requestWrapper.getParamMap());
	}
}
